package flc.ast.adapter;

import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.Random;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.bean.StkResBean;

public class TutorialAdapter extends StkProviderMultiAdapter<StkResBean> {

    public TutorialAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(150));
        addItemProvider(new TutorialProvider());
    }

    private class TutorialProvider extends BaseItemProvider<StkResBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_tutorial;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, StkResBean bean) {
            Glide.with(getContext()).load(bean.getThumbUrl())
                    .into((ImageView) baseViewHolder.getView(R.id.ivTutorialItemImg));
            baseViewHolder.setText(R.id.tvTutorialItemName, bean.getName());
            Random random = new Random();
            int num1 = random.nextInt(9);
            int num2 = random.nextInt(9);
            baseViewHolder.setText(R.id.tvTutorialItemNum, getContext().getString(R.string.read_num, num1, num2));
        }

    }
}
